package accel.activities;

import accel.dataholders.Character;
import accel.dataholders.Weapon;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class CharacterScreenActivity extends Activity {

	private TextView wname, str,ener,heal, cha, spe, sname, str2,ener2,heal2, cha2, spe2, str3,ener3,heal3, cha3, spe3, ls, ls2, ls3, lvl, exp;
	private Character [] cs;
	private ImageView wimage, portrait;
	
	@Override
	public void onCreate(Bundle savedState)
	{
		super.onCreate(savedState);
		this.setContentView(R.layout.characterscreen);
		str = (TextView)findViewById(R.id.strength);
        ener = (TextView)findViewById(R.id.energy);
        heal = (TextView)findViewById(R.id.health);
        cha = (TextView)findViewById(R.id.charisma);
        spe = (TextView)findViewById(R.id.speed);
        ls = (TextView)findViewById(R.id.lspeed);
        
        str2 = (TextView)findViewById(R.id.strength2);
        ener2 = (TextView)findViewById(R.id.energy2);
        heal2 = (TextView)findViewById(R.id.health2);
        cha2 = (TextView)findViewById(R.id.charisma2);
        spe2 = (TextView)findViewById(R.id.speed2);
        ls2 = (TextView)findViewById(R.id.lspeed2);
        
        str3 = (TextView)findViewById(R.id.strength3);
        ener3 = (TextView)findViewById(R.id.energy3);
        heal3 = (TextView)findViewById(R.id.health3);
        cha3 = (TextView)findViewById(R.id.charisma3);
        spe3 = (TextView)findViewById(R.id.speed3);
        ls3 = (TextView)findViewById(R.id.lspeed3);
       
        lvl = (TextView)findViewById(R.id.level);
        exp = (TextView)findViewById(R.id.exp);
        sname = (TextView)findViewById(R.id.soulName);
        wname = (TextView)findViewById(R.id.weaponName);
        
        wimage = (ImageView)findViewById(R.id.weaponImage);
        portrait = (ImageView)findViewById(R.id.portrait);
        
        Character soul = Character.instance;
		Weapon weapon = Character.instance.getWeapon();
        
        portrait.setImageResource(soul.getPortrait());
        wimage.setImageResource(weapon.getPortrait());
        
        
		sname.setText(getString(soul.getName()));
		
		str.setText(Integer.toString(soul.getStats().maxstrength));
		ener.setText(Integer.toString(soul.getStats().maxenergy));
		heal.setText(Integer.toString(soul.getStats().maxhealth));
		cha.setText(Integer.toString(soul.getStats().maxcharisma));
		spe.setText(Integer.toString(soul.getStats().maxspeed));
		ls.setText(Integer.toString(soul.getStats().maxlearningspeed));
		
		setValues(soul.getStats().maxstrength, weapon.getStats().maxstrength, str2, str3);
		setValues(soul.getStats().maxenergy, weapon.getStats().maxenergy, ener2, ener3);
		setValues(soul.getStats().maxhealth, weapon.getStats().maxhealth, heal2, heal3);
		setValues(soul.getStats().maxcharisma, weapon.getStats().maxcharisma, cha2, cha3);
		setValues(soul.getStats().maxspeed, weapon.getStats().maxspeed, spe2, spe3);
		setValues(soul.getStats().maxlearningspeed, weapon.getStats().maxlearningspeed, ls2, ls3);
		
		wimage.setImageResource(weapon.getPortrait());
		wname.setText(getString(weapon.getName()));
		
		lvl.setText(Integer.toString(soul.getLevel()));
		exp.setText(Integer.toString(soul.getExp()) + " / " + Integer.toString(soul.expForNextLevel()));
        
	}
	
	private void setValues(int a, int b, TextView tx1, TextView tx2) //a - soul.stats, b - weapon.stats
	{
		if (b > 0)
		{
			tx1.setText("+" + Integer.toString(b));
			tx1.setTextColor(Color.GREEN);
			tx2.setText(Integer.toString(a + b));
			tx2.setBackgroundColor(Color.GREEN);
		}
		else if (b == 0)
		{
			tx1.setText("0");
			tx1.setTextColor(Color.GRAY);
			tx2.setText(Integer.toString(a));
			tx2.setBackgroundColor(Color.TRANSPARENT);
		}
		else
		{
			tx1.setText(Integer.toString(b));
			tx1.setTextColor(Color.RED);
			tx2.setText(Integer.toString(a + b));
			tx2.setBackgroundColor(Color.RED);
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.characterscreen_menu, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId())
		{
		case R.id.showSoulDesc:
			
			return true;
		case R.id.showWeaponDesc:
			
			return true;
		default:
            return super.onOptionsItemSelected(item);
		}
	}
	
	public void train(View v)
	{
		startActivity(new Intent(this, TrainingActivity.class));
	}
}
